package com.treetao.union.db.service.impl;

import com.treetao.union.db.model.MallOrderDetail;
import com.treetao.union.db.mapper.MallOrderDetailMapper;
import com.treetao.union.db.service.MallOrderDetailService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 订单明细 服务实现类
 * </p>
 *
 * @author Dev.M
 * @since 2020-04-11
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MallOrderDetailServiceImpl extends ServiceImpl<MallOrderDetailMapper, MallOrderDetail>
		implements MallOrderDetailService {

	@Override
	public MallOrderDetail getDetail(Long orderno, Long skuId) {
		QueryWrapper<MallOrderDetail> q = new QueryWrapper<MallOrderDetail>();
		q.eq("orderno", orderno);
		q.eq("sku_id", skuId);
		return getOne(q);
	}

	@Override
	public boolean finishAllComment(Long orderno) {
		QueryWrapper<MallOrderDetail> q = new QueryWrapper<MallOrderDetail>();
		q.eq("orderno", orderno);
		q.eq("commented", false);
		return count(q) == 0;
	}

	@Override
	public List<MallOrderDetail> getDetails(Long orderno) {
		QueryWrapper<MallOrderDetail> q = new QueryWrapper<MallOrderDetail>();
		q.eq("orderno", orderno);
		return list(q);
	}

}
